package com.wh.hotel.controller;

import com.wh.common.annotation.ResultLog;
import com.wh.common.enums.MethodTypeEnum;
import com.wh.hotel.alone.CircleService;
import com.wh.hotel.convert.HotelStructConvert;
import com.wh.hotel.dao.HotelPricingStrategyDao;
import com.wh.hotel.model.HotelPricingStrategy;
import com.wh.hotel.model.HotelTest;
import com.wh.hotel.service.TestService;
import com.wh.hotel.service.strategy.PriceStrategyFactory;
import com.wh.hotel.util.DateWhUtil;
import com.wh.hotel.vo.HotelPriceStrategyVo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.Date;

/**
 * @author luweije
 */
@RequestMapping("/test")
@RestController
@Slf4j
public class TestController {

    @Resource
    private TestService testService;

    @Resource
    private CircleService circleService;

    @Resource
    private PriceStrategyFactory priceStrategyFactory;

    @Resource
    private HotelStructConvert hotelStructConvert;

    @Resource
    private HotelPricingStrategyDao hotelPricingStrategyDao;


    @GetMapping("/testPrice")
    @ResultLog(name = "TestController.testPrice", methodType = MethodTypeEnum.HTTP_UP)
    public Object testPrice(Long strategyId) {
        HotelPricingStrategy hotelPricingStrategy = hotelPricingStrategyDao.selectById(strategyId);
        HotelPriceStrategyVo strategyVo = hotelStructConvert.convertToHotelPriceStrategyVo(hotelPricingStrategy);
        Date today = DateWhUtil.dayStart(new Date());
        return priceStrategyFactory.calculateValidTime(strategyVo, today, DateWhUtil.addDays(today, 15));
    }


    @GetMapping("/first")
    @ResultLog(name = "TestController.first", methodType = MethodTypeEnum.HTTP_UP)
    public Object first() {
        HotelTest hotelTest = new HotelTest();
        hotelTest.setUid(11L);
        hotelTest.setNickname("hahah");
        return testService.insert(hotelTest);
    }

    @GetMapping("/circle")
    public Object circle() {
        log.info("controller");
        circleService.testCircle();
        return "success";
    }
}
